﻿namespace GoogleOAuthTest
{
    using System.Windows;
    using System.Windows.Input;

    using GoogleOAuth.Models;

    public partial class MainPage
    {
        private const string Callback = "https://asylum.azure-mobile.net/login/google";
        public const string Clientid = "246053357164";
        public const string ClientSecret = "b5r6eQJjs3oRcBmWBGBDt1DJ";

        public MainPage()
        {
            InitializeComponent();
        }
        
        private void OnGoogleLogin(object sender, GestureEventArgs e)
        {
            IGoogleClient client = new GoogleClient();
            client.Initialize(AuthBrowser, Clientid, ClientSecret, Callback);
            client.AuthenticationCompleted += ClientOnAuthenticationCompleted;
            client.LoginAsync();
            AuthBrowser.Visibility = Visibility.Visible;
            InfoPanel.Visibility = Visibility.Collapsed;
        }

        private void ClientOnAuthenticationCompleted(object sender, GoogleAccount account)
        {
            InfoPanel.Visibility = Visibility.Visible;
            AuthBrowser.Visibility = Visibility.Collapsed;
            if (account == null) return;
            Email.Text = account.Email;
            Id.Text = account.Id;
            Name.Text = account.Name;
        }
    }
}